import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 * 
 */

/**
 * @author inaki_torres
 *
 */
public class GestionTareasMemoria implements GestionTareas {

	Hashtable<Integer,Tarea> listaTareas= new Hashtable<Integer,Tarea>();
	/* (non-Javadoc)
	 * @see GestionTareas#introducirTarea(java.lang.String)
	 */
	@Override
	public int introducirTarea(String tarea) {
		Tarea ta= new Tarea(listaTareas.size()+1,tarea);
		Integer id=new Integer(listaTareas.size()+1);
		listaTareas.put(id, ta);
		return id;
	}

	/* (non-Javadoc)
	 * @see GestionTareas#eliminarTarea(int)
	 */
	@Override
	public void eliminarTarea(int id) {
		if (listaTareas.containsKey(id)){
			listaTareas.remove(id);
		}
	}

	/* (non-Javadoc)
	 * @see GestionTareas#modificarTarea(Tarea)
	 */
	@Override
	public void modificarTarea(Tarea tarea) {
		if (listaTareas.contains(tarea)){
			listaTareas.get(tarea.getId()).setTarea(tarea.getTarea());
		}

	}

	/* (non-Javadoc)
	 * @see GestionTareas#buscarTarea(int)
	 */
	@Override
	public Tarea buscarTarea(int id) {
		if (listaTareas.containsKey(id)){
			return listaTareas.get(id);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see GestionTareas#listaTareas()
	 */
	@Override
	public Vector<Tarea> listaTareas() {
		Vector<Tarea> dev = new Vector<Tarea>();
		Enumeration<Integer> keys=listaTareas.keys();
		while(keys.hasMoreElements()){
			dev.add(listaTareas.get(keys.nextElement()));
		}
		return dev;
	}

}
